﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.ModFlow.Domain.DomainLayer;


namespace HA.Data
{
    /// <summary>
    /// 检查modflow
    /// </summary>
    public class CheckModflow : ModelFacotry
    {
        #region 构造函数

        public CheckModflow(ModFlowData mfData)
        {

            _mfData = mfData;

            if (this._modelCheckResult != null)
            {
                _modelCheckResult.Clear();
            }
            else
            {
                _modelCheckResult = new List<CheckResultMessage>();
            }

        }

        #endregion


        #region 字段属性

        ModFlowData _mfData;

        #endregion



        public override List<CheckResultMessage> CheckModelData(ListDisplaySetup displaySetup)
        {
            if (this._modelCheckResult != null)
            {
                _modelCheckResult.Clear();
            }
            else
            {
                _modelCheckResult = new List<CheckResultMessage>();
            }

            //遍历各个包 根据各个包的规则进行Check  将信息添加入  this._modelCheckResult   返回


            List<CheckResultMessage> arry = new List<CheckResultMessage>();
            arry = CheckBASICPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);


            arry = CheckDisPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckConstandHeadPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckWellPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckLpfPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckBcfPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckRiverPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckDrainPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckGeneralHeadPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckRechargePackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            arry = CheckEVTPackage(displaySetup);
            this._modelCheckResult.AddRange(arry);

            return this._modelCheckResult;

           
            //throw new NotImplementedException();
        }


        #region





        /// <summary>
        /// basic包
        /// </summary>
        private List<CheckResultMessage> CheckBASICPackage(ListDisplaySetup displaySetup)
        {
            //W1,：某一层的初始水头不能全部为0。
            //E1：下一层单个网格的初始水头不能低于本层同等网格的底部海拔

            List<CheckResultMessage> basicMessage = new List<CheckResultMessage>();
            if (displaySetup == null)
            {
                return basicMessage;
            }

            if (this._mfData != null)
            {

                if (this._mfData.GridData != null)
                {
                    if (this._mfData.GridData.WaterGrid != null)
                    {
                        try
                        {

                            List<double[,]> initHead = this._mfData.GridData.WaterGrid.GetInitHead();

                            if (displaySetup.IsSuppressWarnings == false)
                            {
                                #region    W1,：某一层的初始水头不能全部为0。
                                for (int layer = 0; layer < initHead.Count; layer++)
                                {
                                    bool isAllZero = IsLayerDataIsAllZero(initHead[layer]);
                                    if (isAllZero)
                                    {
                                        string messageStr = CheckErrorType.Warning.ToString() + "   " + PackageType.BASIC_mf.ToString() + "  " + ErrorType.AllZero.ToString() + "   第" + (layer+1).ToString() + "  " + "层网格单元的初始水头值不能全部为0。";
                                        CheckResultMessage message = new CheckResultMessage(CheckErrorType.Warning, PackageType.BASIC_mf, ErrorType.AllZero);
                                        message.SetMessage(messageStr);

                                        basicMessage.Add(message);
                                    }
                                }

                                #endregion
                            }

                            List<double[,]> elevation = this._mfData.GridData.Elevations;

                            #region   E1：单个网格的初始水头不能低于本层同等网格的底部海拔

                            if (displaySetup.IsDisplayAllErrors)
                            {
                                for (int layer = 0; layer < initHead.Count; layer++)
                                {
                                    bool isHas = IsFirstHasDataLowerThanSecondData(initHead[layer], elevation[layer + 1]);
                                    if (isHas)
                                    {

                                        string messageStr = CheckErrorType.Error.ToString() + "  " + PackageType.BASIC_mf.ToString() + "   " + ErrorType.HeadAndElevation.ToString() + "   第" + (layer+1).ToString() + " " + "层网格单元的底部高程不能高于对应的单元格的水头值。";
                                        CheckResultMessage message = new CheckResultMessage(CheckErrorType.Error, PackageType.BASIC_mf, ErrorType.HeadAndElevation);
                                        message.SetMessage(messageStr);

                                        basicMessage.Add(message);
                                    }
                                }
                            }
                            else
                            {
                                int number = 0;
                                for (int layer = 0; layer < initHead.Count; layer++)
                                {

                                    bool isHas = IsFirstHasDataLowerThanSecondData(initHead[layer], elevation[layer + 1]);
                                    if (isHas)
                                    {

                                        string messageStr = CheckErrorType.Error.ToString() + "  " + PackageType.BASIC_mf.ToString() + "   " + ErrorType.HeadAndElevation.ToString() + "   第" + (layer+1).ToString() + " " + "层网格单元的底部高程不能高于对应的单元格的水头值。";
                                        CheckResultMessage message = new CheckResultMessage(CheckErrorType.Error, PackageType.BASIC_mf, ErrorType.HeadAndElevation);
                                        message.SetMessage(messageStr);

                                        basicMessage.Add(message);

                                        number = number + 1;

                                    }
                                    if (number + 1 > displaySetup.DisplayErrorsMaxNum)
                                    {
                                        break;
                                    }
                                }

                            }
                            #endregion


                        }
                        catch
                        {

                            //basicMessage = new List<CheckResultMessage>();
                            return basicMessage;
                        }
                    }

                }

            }

            return basicMessage;

        }


        /// <summary>
        /// 离散包  Dis
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckDisPackage(ListDisplaySetup displaySetup)
        {
            //W1：相连网格的大小相差不能超过50%
            //W2：层的海拔高度如果都是0，则给出警告信息
            //E1：下一层网格单元的海拔高度不能超过当前网格单元的海拔

            List<CheckResultMessage> disMessage = new List<CheckResultMessage>();
            if (displaySetup == null)
            {
                return disMessage;
            }

            if (this._mfData != null)
            {

                if (this._mfData.GridData != null)
                {
                    try
                    {


                        List<double[,]> elevation = this._mfData.GridData.Elevations;

                        #region W1：相连网格的大小相差不能超过50%

                        //同一层相邻的单元格在长度和宽度方向都不可以 
                        //如何定义50%：A长度小，B长度大，A长度不能小于B的一半
                        if (displaySetup.IsSuppressWarnings == false)
                        {
                            int num = 0;
                            double[] xCoor = this._mfData.GridData.ColCoords;
                            double[] yCoor = this._mfData.GridData.RowCoords;
                            if (num <= 0)
                            {
                                if (xCoor.Length  > 2)
                                {
                                    for (int xIndex = 0; xIndex < xCoor.Length; xIndex++)
                                    {
                                        if (xIndex < xCoor.Length - 2)
                                        {
                                            bool isHas = IsFirstLowerThanSecondHalf(xCoor[xIndex], xCoor[xIndex + 1],xCoor [xIndex +2]);
                                            if (isHas)
                                            {
                                                num = num + 1;

                                                break;

                                            }
                                        }
                                    }
                                }
                            }
                            if (num>0)
                            {
                                string messageStr = CheckErrorType.Warning.ToString() + "   " + PackageType.DISCRETIZATION_mf.ToString() + "  " + ErrorType.CellLengthLimit.ToString() + "   " + "相邻单元格的长度或宽度相差不能超过50%。";
                                CheckResultMessage message = new CheckResultMessage(CheckErrorType.Warning, PackageType.DISCRETIZATION_mf, ErrorType.CellLengthLimit);
                                message.SetMessage(messageStr);

                                disMessage.Add(message);
                            }

                            num = 0;
                            if (num <= 0)
                            {
                                if (yCoor.Length > 2)
                                {

                                    for (int yIndex = 0; yIndex < yCoor.Length; yIndex++)
                                    {

                                        if (yIndex < yCoor.Length - 2)
                                        {

                                            bool isHas = IsFirstLowerThanSecondHalf(yCoor[yIndex], yCoor[yIndex + 1],yCoor [yIndex +2]);
                                            if (isHas)
                                            {
                                                num = num + 1;

                                                break;

                                            }
                                        }
                                    }
                                }
                            }
                            if (num >0)
                            {
                                string messageStr = CheckErrorType.Warning.ToString() + "   " + PackageType.DISCRETIZATION_mf.ToString() + "  " + ErrorType.CellLengthLimit.ToString() + "   " + "相邻单元格的长度或宽度相差不能超过50%。";
                                CheckResultMessage message = new CheckResultMessage(CheckErrorType.Warning, PackageType.DISCRETIZATION_mf, ErrorType.CellLengthLimit);
                                message.SetMessage(messageStr);

                                disMessage.Add(message);
                            }

                        }


                        #endregion


                        #region W2：层的海拔高度如果都是0，则给出警告信息
                        if (displaySetup.IsSuppressWarnings == false)
                        {
                            for (int layer = 0; layer < elevation.Count; layer++)
                            {
                                bool isAllZero = IsLayerDataIsAllZero(elevation[layer]);
                                if (isAllZero)
                                {
                                    string messageStr = CheckErrorType.Warning.ToString() + "   " + PackageType.DISCRETIZATION_mf.ToString() + "  " + ErrorType.AllZero.ToString() + "   " + "第" + (layer+1).ToString() + " 层网格高程值不能全部为0。";
                                    CheckResultMessage message = new CheckResultMessage(CheckErrorType.Warning, PackageType.DISCRETIZATION_mf, ErrorType.AllZero);
                                    message.SetMessage(messageStr);
                                    disMessage.Add(message);
                                }
                            }

                        }
                        #endregion


                        #region E1：下一层网格单元的海拔高度不能超过当前网格单元的海拔
                        if (displaySetup.IsDisplayAllErrors)
                        {
                            for (int layer = 0; layer < elevation.Count; layer++)
                            {
                                if (layer < elevation.Count - 1)
                                {
                                    bool isHas = IsFirstHasDataLowerThanSecondData(elevation[layer], elevation[layer + 1]);
                                    if (isHas)
                                    {
                                        string messageStr = CheckErrorType.Error.ToString() + "  " + PackageType.DISCRETIZATION_mf.ToString() + "   " + ErrorType.BotAndTopElevation.ToString() + "   " + "第" + (layer + 1).ToString() + " 层网格单元的底部高程不能高于其顶部高程。";
                                        CheckResultMessage message = new CheckResultMessage(CheckErrorType.Error, PackageType.DISCRETIZATION_mf, ErrorType.BotAndTopElevation);
                                        message.SetMessage(messageStr);

                                        disMessage.Add(message);

                                    }
                                }

                            }
                        }
                        else
                        {
                            int number = 0;
                            for (int layer = 0; layer < elevation.Count; layer++)
                            {
                                if (layer < elevation.Count - 1)
                                {
                                    bool isHas = IsFirstHasDataLowerThanSecondData(elevation[layer], elevation[layer + 1]);
                                    if (isHas)
                                    {
                                        string messageStr = CheckErrorType.Error.ToString() + "  " + PackageType.DISCRETIZATION_mf.ToString() + "   " + ErrorType.BotAndTopElevation.ToString() + "   " + "第" + (layer + 1).ToString() + " 层网格单元的底部高程不能高于其顶部高程。";
                                        CheckResultMessage message = new CheckResultMessage(CheckErrorType.Error, PackageType.DISCRETIZATION_mf, ErrorType.BotAndTopElevation);
                                        message.SetMessage(messageStr);

                                        disMessage.Add(message);
                                        number = number + 1;

                                    }
                                    if (number + 1 > displaySetup.DisplayErrorsMaxNum)
                                    {
                                        break;
                                    }
                                }

                            }


                        }
                        #endregion


                    }
                    catch
                    {

                        return disMessage;
                    }

                }
            }


            return disMessage;

        }

        /// <summary>
        /// 时变水头包
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckConstandHeadPackage(ListDisplaySetup displaySetup)
        {

            //E1：水头值不能低于当前层网格的底层海拔

            List<CheckResultMessage> constantHeadMessage = new List<CheckResultMessage>();
            if (displaySetup == null)
            {
                return constantHeadMessage;
            }

            if (this._mfData != null)
            {
                if (this._mfData.GridData != null)
                {
                    if (this._mfData.SourceSinks != null)
                    {
                        if (this._mfData.SourceSinks.SpecifiedHeads != null)
                        {
                            if (this._mfData.SourceSinks.SpecifiedHeads.Enabled == true)
                            {
                                try
                                {

                                    #region    E1：水头值不能低于当前层网格的底层海拔

                                    if (this._mfData.GridData.WaterGrid != null)
                                    {
                                        List<double[,]> initHead = this._mfData.GridData.WaterGrid.GetInitHead();
                                        List<double[,]> elevation = this._mfData.GridData.Elevations;

                                        if (displaySetup.IsDisplayAllErrors)
                                        {
                                            for (int layer = 0; layer < initHead.Count; layer++)
                                            {
                                                bool isHas = IsFirstHasDataLowerThanSecondData(initHead[layer], elevation[layer + 1]);
                                                if (isHas)
                                                {
                                                    string messageStr = CheckErrorType.Error.ToString() + "  " + PackageType.CONSTANTHEAD_mf.ToString() + "   " + ErrorType.HeadAndElevation.ToString() + "   " + "第" + (layer + 1).ToString() + " 层网格单元的水头值不能低于其底部海拔。";

                                                    CheckResultMessage message = new CheckResultMessage(CheckErrorType.Error, PackageType.CONSTANTHEAD_mf, ErrorType.HeadAndElevation);
                                                    message.SetMessage(messageStr);

                                                    constantHeadMessage.Add(message);

                                                }


                                            }
                                        }
                                        else
                                        {
                                            int num = 0;
                                            for (int layer = 0; layer < initHead.Count; layer++)
                                            {
                                                bool isHas = IsFirstHasDataLowerThanSecondData(initHead[layer], elevation[layer + 1]);
                                                if (isHas)
                                                {
                                                    string messageStr = CheckErrorType.Error.ToString() + "  " + PackageType.CONSTANTHEAD_mf.ToString() + "   " + ErrorType.HeadAndElevation.ToString() + "   " + "第" + (layer + 1).ToString() + " 层网格单元的水头值不能低于其底部海拔。";

                                                    CheckResultMessage message = new CheckResultMessage(CheckErrorType.Error, PackageType.CONSTANTHEAD_mf, ErrorType.HeadAndElevation);
                                                    message.SetMessage(messageStr);

                                                    constantHeadMessage.Add(message);

                                                    num = num + 1;

                                                }
                                                if (num + 1 > displaySetup.DisplayErrorsMaxNum)
                                                {
                                                    break;
                                                }

                                            }

                                        }
                                    }
                                    #endregion


                                }
                                catch
                                {
                                    return constantHeadMessage;
                                }

                            }
                        }
                    }

                }

            }


            return constantHeadMessage;
        }


        /// <summary>
        /// 井包
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckWellPackage(ListDisplaySetup displaySetup)
        {
            //W1：井网格的流量为0的时候，提示警告信息
            List<CheckResultMessage> wellMessage = new List<CheckResultMessage>();
            if (displaySetup == null)
            {
                return wellMessage;
            }
            if (this._mfData != null)
            {
                if (this._mfData.GridData != null)
                {
                    if (this._mfData.SourceSinks != null)
                    {
                        if (this._mfData.SourceSinks.Wells != null)
                        {
                            if (this._mfData.SourceSinks.Wells.Enabled)
                            {
                                try
                                {

                                    #region W1：井网格的流量为0的时候，提示警告信息

                                    if (displaySetup.IsSuppressWarnings == false)
                                    {
                                        for (int i = 0; i < this._mfData.SourceSinks.Wells.InnerList.Count; i++)
                                        {
                                            int zeroNum = 0;
                                            for (int j = 0; j < this._mfData.SourceSinks.Wells.InnerList[i].RechargeRates.Count; j++)
                                            {
                                                if (this._mfData.SourceSinks.Wells.InnerList[i].RechargeRates[j] != 0)
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    zeroNum = zeroNum + 1;
                                                }
                                            }
                                            if (zeroNum == this._mfData.SourceSinks.Wells.InnerList[i].RechargeRates.Count)
                                            {
                                                string messageStr ;
                                                if (this._mfData.SourceSinks.Wells.InnerList[i].Name!=null )
                                                {
                                                    messageStr = CheckErrorType.Warning.ToString() + "  " + PackageType.WELL_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + "井" + "  " + this._mfData.SourceSinks.Wells.InnerList[i].Name + "   的流量为0。";
                                                }
                                                else
                                                {
                                                    messageStr = CheckErrorType.Warning.ToString() + "  " + PackageType.WELL_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   第 " + (i + 1).ToString() + " 个井" + " 的流量为0。";
                                                }
                                                CheckResultMessage message = new CheckResultMessage(CheckErrorType.Warning, PackageType.WELL_mf, ErrorType.AllZero);
                                                message.SetMessage(messageStr);

                                                wellMessage.Add(message);

                                            }


                                        }
                                    }


                                    #endregion

                                }
                                catch
                                {
                                    return wellMessage;
                                }

                            }

                        }
                    }
                }
            }
            return wellMessage;
        }



        #region 小齐

        /// <summary>
        /// 判断一个三维数据中的每一个数值是否为0,默认为true
        /// </summary>
        /// <param name="data"></param>
        /// <param name="index">第N层数据</param>
        /// <returns></returns>
        private bool IsZero(double[, ,] data,int index)
        {
            bool b=true ;
            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    if (data[i, j, index] != 0)
                    {
                        b = false ;
                        return b ;
                    }
                }
            }
            return b;
        }

        /// <summary>
        /// 判断一个三维数据中的每一个数值是否大于0,默认为F
        /// </summary>
        /// <param name="data"></param>
        /// <param name="index">第N层数据</param>
        /// <returns></returns>
        private bool IsGreaterThanZero(double[, ,] data, int index)
        {
            bool b = false;
            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    if (data[i, j, index] < 0)
                    {
                        b = true;
                        return b;
                    }
                }
            }
            return b;
        }


        private List<CheckResultMessage> CheckLpfPackage(ListDisplaySetup dispalySetup)
        {

            //    E1 ：LPF的层数据即hk、vkA、Hani、SS、Sy、vkcb均不能设为0，并且均不能小于0。对于各要素分别进行提醒。


            List<CheckResultMessage> lpfMessage = new List<CheckResultMessage>();

            List<CheckResultMessage> hkZero = new List<CheckResultMessage>();
            List<CheckResultMessage> vkaZero = new List<CheckResultMessage>();
            List<CheckResultMessage> hainZero = new List<CheckResultMessage>();
            List<CheckResultMessage> ssZero = new List<CheckResultMessage>();
            List<CheckResultMessage> syZero = new List<CheckResultMessage>();
            List<CheckResultMessage> vkcbZero = new List<CheckResultMessage>();

            List<CheckResultMessage> hkLowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> vkaLowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> hainLowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> ssLowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> syLowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> vkcbLowerZero = new List<CheckResultMessage>();


            if (dispalySetup == null)
            {
                return lpfMessage;
            }
            if (dispalySetup.IsSuppressWarnings)
            {
                return lpfMessage;
            }
            if (this._mfData != null)
            {
                if (this._mfData.GridData != null)
                {
                    if (this._mfData.ModelOption != null)
                    {
                        if (this._mfData.ModelOption.InnerPack == INNERPACK.LPF)
                        {
                            #region W1 ：LPF的层数据即hk、vkA、Hani、SS、Sy、vkcb均不能设为0，并且均不能小于0。对于各要素分别进行提醒。


                            double[, ,] datas = this._mfData.FlowData.LpfData.Parent.Hk.Datas;

                            //此字段不需要考虑哪种类型        HK                           
                            for (int k = 0; k < datas.GetLength(2); k++)
                            {
                                bool b = IsZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.AllZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的水平水力传导系数数据值不能都为0";
                                    checkResult.SetMessage(str);
                                    hkZero.Add(checkResult);
                                }
                                b = IsGreaterThanZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.LowerThanZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的水平水力传导系数数据值都不能小于0";
                                    checkResult.SetMessage(str);
                                    hkLowerZero.Add(checkResult);
                                }
                            }

                            //VKA
                            datas = this._mfData.FlowData.LpfData.Vka.Datas;
                            for (int k = 0; k < datas.GetLength(2); k++)
                            {
                                bool b = IsZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.AllZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的垂向水力传导系数数据值不能都为0";
                                    checkResult.SetMessage(str);
                                    vkaZero.Add(checkResult);
                                }
                                b = IsGreaterThanZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.LowerThanZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的垂向水力传导系数数据值都不能小于0";
                                    checkResult.SetMessage(str);
                                    vkaLowerZero.Add(checkResult);
                                }
                            }


                            //Hani
                            datas = this._mfData.FlowData.LpfData.Hani.Datas;

                            for (int k = 0; k < datas.GetLength(2); k++)
                            {
                                bool b = IsZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.AllZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的水平各向异性数据值不能都为0";
                                    checkResult.SetMessage(str);
                                    hainZero.Add(checkResult);
                                }
                                b = IsGreaterThanZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.LowerThanZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的水平各向异性数据值都不能小于0";
                                    checkResult.SetMessage(str);
                                    hainLowerZero.Add(checkResult);
                                }
                            }


                            //Ss 瞬态应力期
                            if (this._mfData.FlowData.IsHaveTransient)
                            {
                                datas = this._mfData.FlowData.LpfData.Ss.Datas;
                                for (int k = 0; k < datas.GetLength(2); k++)
                                {
                                    bool b = IsZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.AllZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的比容量数据值不能都为0";
                                        checkResult.SetMessage(str);
                                        ssZero.Add(checkResult);
                                    }
                                    b = IsGreaterThanZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.LowerThanZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的比容量数据值都不能小于0";
                                        checkResult.SetMessage(str);
                                        ssLowerZero.Add(checkResult);
                                    }
                                }

                            }

                            //Sy 瞬态应力期
                            if (this._mfData.FlowData.IsHaveTransient)
                            {
                                datas = this._mfData.FlowData.LpfData.Sy.Datas;
                                for (int k = 0; k < datas.GetLength(2); k++)
                                {
                                    if (this._mfData.FlowData.LpfData.Layers[k].LayerType != LPFLAYERTYPE.CONFINED)
                                    {
                                        bool b = IsZero(datas, k);
                                        if (b)
                                        {
                                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.AllZero);
                                            string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的单位产水量数据值不能都为0";
                                            checkResult.SetMessage(str);
                                            syZero.Add(checkResult);
                                        }
                                        b = IsGreaterThanZero(datas, k);
                                        if (b)
                                        {
                                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.LowerThanZero);
                                            string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的单位产水量数据值都不能小于0";
                                            checkResult.SetMessage(str);
                                            syLowerZero.Add(checkResult);
                                        }
                                    }
                                }
                            }

                            //VKCB 瞬态应力期                          
                            datas = this._mfData.FlowData.LpfData.Vkcb.Datas;

                            for (int k = 0; k < datas.GetLength(2) - 1; k++)
                            {
                                //是否是隔水层
                                if (this._mfData.GridData.WaterGrid[k].IsHaveConfiningBed)
                                {
                                    bool b = IsZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.AllZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的隔水层垂向导水系数数据值不能都为0";
                                        checkResult.SetMessage(str);
                                        vkcbZero.Add(checkResult);
                                    }
                                    b = IsGreaterThanZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.LowerThanZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层LPF 网格单元的隔水层垂向导水系数数据值都不能小于0";
                                        checkResult.SetMessage(str);
                                        vkcbLowerZero.Add(checkResult);
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
            }

            #region 以前的错误信息

            //if (dispalySetup.IsDisplayAllErrors)
            //{
            //    lpfMessage.AddRange(hkZero);
            //    lpfMessage.AddRange(vkaZero);
            //    lpfMessage.AddRange(hainZero);
            //    lpfMessage.AddRange(ssZero);
            //    lpfMessage.AddRange(syZero);
            //    lpfMessage.AddRange(vkcbZero);

            //    lpfMessage.AddRange(hkLowerZero);
            //    lpfMessage.AddRange(vkaLowerZero);
            //    lpfMessage.AddRange(hainLowerZero);
            //    lpfMessage.AddRange(ssLowerZero);
            //    lpfMessage.AddRange(syLowerZero);
            //    lpfMessage.AddRange(vkcbLowerZero);
            //}
            //else
            //{
            //    for (int i = 0; i < hkZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(hkZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < vkaZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(vkaZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < hainZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(hainZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < ssZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(ssZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < syZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(syZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < vkcbZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(vkcbZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < hkLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(hkLowerZero[i]);
            //        }
            //    }
            //    for (int i = 0; i < vkaLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(vkaLowerZero[i]);
            //        }
            //    }
            //    for (int i = 0; i < hainLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(hainLowerZero[i]);
            //        }
            //    }
            //    for (int i = 0; i < ssLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(ssLowerZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < syLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(syLowerZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < vkcbLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= dispalySetup.DisplayErrorsMaxNum)
            //        {
            //            lpfMessage.Add(vkcbLowerZero[i]);
            //        }
            //    }
            //}
            #endregion

            lpfMessage.AddRange(hkZero);
            lpfMessage.AddRange(vkaZero);
            lpfMessage.AddRange(hainZero);
            lpfMessage.AddRange(ssZero);
            lpfMessage.AddRange(syZero);
            lpfMessage.AddRange(vkcbZero);

            lpfMessage.AddRange(hkLowerZero);
            lpfMessage.AddRange(vkaLowerZero);
            lpfMessage.AddRange(hainLowerZero);
            lpfMessage.AddRange(ssLowerZero);
            lpfMessage.AddRange(syLowerZero);
            lpfMessage.AddRange(vkcbLowerZero);
            return lpfMessage;

        }

        private List<CheckResultMessage> CheckBcfPackage(ListDisplaySetup displaySetup)
        {
            //E1 ：BCF的层数据即SF1、tran、HY、sf2、Sy、vkcb均不能设为0，并且均不能小于0。对于各要素分别进行提醒。
            //E2：层类型Ltype =1，非承压含水层，只能用于第一层  已经移动到界面进行控制
            List<CheckResultMessage> bcfMessage = new List<CheckResultMessage>();

            List<CheckResultMessage> sf1Zero = new List<CheckResultMessage>();
            List<CheckResultMessage> tranZero = new List<CheckResultMessage>();
            List<CheckResultMessage> sf2Zero = new List<CheckResultMessage>();
            List<CheckResultMessage> hkZero = new List<CheckResultMessage>();
            List<CheckResultMessage> vkcbZero = new List<CheckResultMessage>();

            List<CheckResultMessage> sf1LowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> tranLowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> sf2LowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> hkLowerZero = new List<CheckResultMessage>();
            List<CheckResultMessage> vkcbLowerZero = new List<CheckResultMessage>();

            if (displaySetup == null)
            {
                return bcfMessage;
            }
            if (displaySetup.IsSuppressWarnings)
            {
                return bcfMessage;
            }

            if (this._mfData != null)
            {
                if (this._mfData.GridData != null)
                {

                    if (this._mfData.ModelOption != null)
                    {
                        if (this._mfData.ModelOption.InnerPack == INNERPACK.BCF)
                        {
                            #region W1 ：BCF的层数据即SF1、tran、HY、sf2、Sy、vkcb均不能设为0，并且均不能小于0。对于各要素分别进行提醒。
                         

                            double[, ,] datas = this._mfData.FlowData.BcfData.PrimaryStorage.Datas;
                            //SF1
                            if (this._mfData.FlowData.IsHaveTransient)
                            {
                                for (int k = 0; k < datas.GetLength(2); k++)
                                {
                                    bool b = IsZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.AllZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 第一类贮水系数网格单元的数据值不能都为0";
                                        checkResult.SetMessage(str);
                                        sf1Zero.Add(checkResult);
                                    }
                                    b = IsGreaterThanZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.LPF_mf, ErrorType.LowerThanZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.LPF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 第一类贮水系数网格单元的数据值都不能小于0";
                                        checkResult.SetMessage(str);
                                        sf2LowerZero.Add(checkResult);
                                    }
                                }
                            }

                            datas = this._mfData.FlowData.BcfData.Transmissivity.Datas;
                            for (int k = 0; k < datas.GetLength(2); k++)
                            {
                                if (this._mfData.FlowData.BcfData.Layers[k].LayerType == BCFLAYERTYPE.CONFINED || this._mfData.FlowData.BcfData.Layers[k].LayerType == BCFLAYERTYPE.TRANSMISSITYCONSTANT)
                                {
                                    bool b = IsZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.AllZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 导水系数网格单元的数据值不能都为0";
                                        checkResult.SetMessage(str);
                                        tranZero.Add(checkResult);
                                    }
                                    b = IsGreaterThanZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.LowerThanZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 导水系数网格单元的数据值都不能小于0";
                                        checkResult.SetMessage(str);
                                        tranLowerZero.Add(checkResult);
                                    }
                                }
                            }


                            datas = this._mfData.FlowData.BcfData.Parent.Hk.Datas;
                            for (int k = 0; k < datas.GetLength(2); k++)
                            {
                                if (this._mfData.FlowData.BcfData.Layers[k].LayerType == BCFLAYERTYPE.NOCONFINED || this._mfData.FlowData.BcfData.Layers[k].LayerType == BCFLAYERTYPE.TRANSMISSITYVARY)
                                {
                                    bool b = IsZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.AllZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 渗透系数网格单元的数据值不能都为0";
                                        checkResult.SetMessage(str);
                                        hkZero.Add(checkResult);
                                    }
                                    b = IsGreaterThanZero(datas, k);
                                    if (b)
                                    {
                                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.LowerThanZero);
                                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 渗透系数网格单元的数据值都不能小于0";
                                        checkResult.SetMessage(str);
                                        hkLowerZero.Add(checkResult);
                                    }
                                }
                            }


                            datas = this._mfData.FlowData.BcfData.SecondaryStorage.Datas;
                            if (this._mfData.FlowData.IsHaveTransient)
                            {
                                for (int k = 0; k < datas.GetLength(2); k++)
                                {
                                    if (this._mfData.FlowData.BcfData.Layers[k].LayerType == BCFLAYERTYPE.TRANSMISSITYCONSTANT || this._mfData.FlowData.BcfData.Layers[k].LayerType == BCFLAYERTYPE.TRANSMISSITYVARY)
                                    {
                                        bool b = IsZero(datas, k);
                                        if (b)
                                        {
                                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.AllZero);
                                            string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 第二类贮水系数网格单元的数据值不能都为0";
                                            checkResult.SetMessage(str);
                                            sf2Zero.Add(checkResult);
                                        }
                                        b = IsGreaterThanZero(datas, k);
                                        if (b)
                                        {
                                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.LowerThanZero);
                                            string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 第二类贮水系数网格单元的数据值都不能小于0";
                                            checkResult.SetMessage(str);
                                            sf2LowerZero.Add(checkResult);
                                        }
                                    }
                                }
                            }

                            datas = this._mfData.FlowData.BcfData.Leakance.Datas;
                            for (int k = 0; k < datas.GetLength(2) - 1; k++)
                            {
                                bool b = IsZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.AllZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 垂向水力传导率网格单元的数据值不能都为0";
                                    checkResult.SetMessage(str);
                                    vkcbZero.Add(checkResult);
                                }
                                b = IsGreaterThanZero(datas, k);
                                if (b)
                                {
                                    CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.BCF_mf, ErrorType.LowerThanZero);
                                    string str = CheckErrorType.Warning.ToString() + "  " + PackageType.BCF_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + (k + 1).ToString() + "   " + "层BCF 垂向水力传导率网格单元的数据值小于0";
                                    checkResult.SetMessage(str);
                                    vkcbLowerZero.Add(checkResult);
                                }
                            }

                            #endregion
                        }
                    }
                }
            }

            #region 以前错误信息
            //if (displaySetup.IsDisplayAllErrors)
            //{
            //    bcfMessage.AddRange(sf1Zero);
            //    bcfMessage.AddRange(tranZero);
            //    bcfMessage.AddRange(sf2Zero);
            //    bcfMessage.AddRange(hkZero);
            //    bcfMessage.AddRange(vkcbZero);


            //    bcfMessage.AddRange(sf1LowerZero);
            //    bcfMessage.AddRange(tranLowerZero);
            //    bcfMessage.AddRange(sf2LowerZero);
            //    bcfMessage.AddRange(hkLowerZero);
            //    bcfMessage.AddRange(vkcbLowerZero);
            //}
            //else
            //{
            //    for (int i = 0; i < sf1Zero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(sf1Zero[i]);
            //        }
            //    }

            //    for (int i = 0; i < tranZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(tranZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < sf2Zero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(sf2Zero[i]);
            //        }
            //    }

            //    for (int i = 0; i < hkZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(hkZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < vkcbZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(vkcbZero[i]);
            //        }
            //    }


            //    for (int i = 0; i < sf1LowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(sf1LowerZero[i]);
            //        }
            //    }
            //    for (int i = 0; i < tranLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(tranLowerZero[i]);
            //        }
            //    }
            //    for (int i = 0; i < sf2LowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(sf2LowerZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < hkLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(hkLowerZero[i]);
            //        }
            //    }

            //    for (int i = 0; i < vkcbLowerZero.Count; i++)
            //    {
            //        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
            //        {
            //            bcfMessage.Add(vkcbLowerZero[i]);
            //        }
            //    }
            //}
            #endregion

            
            bcfMessage.AddRange(sf1Zero);
            bcfMessage.AddRange(tranZero);
            bcfMessage.AddRange(sf2Zero);
            bcfMessage.AddRange(hkZero);
            bcfMessage.AddRange(vkcbZero);


            bcfMessage.AddRange(sf1LowerZero);
            bcfMessage.AddRange(tranLowerZero);
            bcfMessage.AddRange(sf2LowerZero);
            bcfMessage.AddRange(hkLowerZero);
            bcfMessage.AddRange(vkcbLowerZero);
            return bcfMessage;
        }

        /// <summary>
        /// River包
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckRiverPackage(ListDisplaySetup displaySetup)
        {

            List<CheckResultMessage> arryCheck = new List<CheckResultMessage>();

            List<CheckResultMessage> stage = new List<CheckResultMessage>();
            List<CheckResultMessage> condu = new List<CheckResultMessage>();

            // E1：网格单元的水头Stage不能低于河床底部海拔
            if (this._mfData != null)
            {
                if (!this._mfData.SourceSinks.Rivers.Enabled)
                {
                    return arryCheck;
                }
                List<double[,]> elevation = new List<double[,]>();
                for (int i = 1; i < this._mfData.GridData.Elevations.Count; i++)
                {
                    elevation.Add(this._mfData.GridData.Elevations[i]);
                }
                List<River> rivers = this._mfData.SourceSinks.Rivers.InnerList;

                //全部错误数据
                for (int i = 0; i < rivers.Count; i++)
                {
                    if (rivers[i].FirstStage < elevation[rivers[i].K - 1][rivers[i].I - 1, rivers[i].J - 1])
                    {
                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Error, PackageType.RIVER_mf, ErrorType.HeadAndElevation);
                        string str = CheckErrorType.Error.ToString() + "  " + PackageType.RIVER_mf.ToString() + "   " + ErrorType.HeadAndElevation.ToString() + "   " + rivers[i].K.ToString() + "   " + "层"+rivers [i].Index+ "单元格的网格底部高程值不能大于河流的Stage值。";
                        checkResult.SetMessage(str);
                        stage.Add(checkResult);
                    }
                    //E2：网格单元的河床导水系数Cond不能为负值
                    if (rivers[i].FirstConductance < 0)
                    {
                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Error, PackageType.RIVER_mf, ErrorType.LowerThanZero);
                        string str = CheckErrorType.Error.ToString() + "  " + PackageType.RIVER_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + rivers[i].K.ToString() + "   " + "层" + rivers[i].Index + "单元格的网格河床导水系数Cond不能为负值。";
                        checkResult.SetMessage(str);
                        condu.Add(checkResult);
                    }
                }




                if (displaySetup.IsDisplayAllErrors)
                {
                    arryCheck.AddRange(stage);
                    arryCheck.AddRange(condu);                                
                }
                else
                {
                    for (int i = 0; i < stage.Count; i++)
                    {
                        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
                        {
                            arryCheck.Add(stage[i]);
                        }
                    }
                    for (int i = 0; i < condu.Count; i++)
                    {
                        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
                        {
                            arryCheck.Add(condu[i]);
                        }
                    }
                }
            }
            return arryCheck;
        }
        /// <summary>
        /// Drain包
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckDrainPackage(ListDisplaySetup displaySetup)
        {
            //E1：网格单元的排水渠和含水层界面的水力传导系数Cond不能为负值
            List<CheckResultMessage> arryCheck = new List<CheckResultMessage>();       

            if (this._mfData != null)
            {
                if (!this._mfData.SourceSinks.Drains.Enabled)
                {
                    return arryCheck;
                }

                List<Drain> drains = this._mfData.SourceSinks.Drains.InnerList;
                for (int i = 0; i < drains.Count; i++)
                {
                    if (drains[i].FirstConductance < 0)
                    {
                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Error, PackageType.DRAIN_mf, ErrorType.LowerThanZero);
                        string str = CheckErrorType.Error.ToString() + "  " + PackageType.DRAIN_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + drains[i].K.ToString() + "   " + "层"+drains[i].Index+"单元格的网格含水层界面的水力传导系数Conductance不能为负值。";
                        checkResult.SetMessage(str);
                        arryCheck.Add(checkResult);
                    }
                }

                if (displaySetup.IsDisplayAllErrors)
                {
                    return arryCheck;
                }
                else
                {
                    List<CheckResultMessage> arryCheckCount = new List<CheckResultMessage>();
                    for (int i = 0; i < arryCheck.Count ; i++)
                    {
                        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
                        {
                            arryCheckCount.Add(arryCheck[i]);
                        }
                    }
                    return arryCheckCount;
                }
            }
            return arryCheck;
        }
        /// <summary>
        /// GeneralHead包
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckGeneralHeadPackage(ListDisplaySetup displaySetup)
        {
            List<CheckResultMessage> arryCheck = new List<CheckResultMessage>();

            List<CheckResultMessage> condu = new List<CheckResultMessage>();
            List<CheckResultMessage> conduLowerZero = new List<CheckResultMessage>();

            if (this._mfData != null)
            {
                if (!this._mfData.SourceSinks.GeneralHeads.Enabled)
                {
                    return arryCheck;
                }
                // E1：网格单元的通用水头Stage不能低于单元底部海拔
                List<double[,]> elevation = new List<double[,]>();
                for (int i = 1; i < this._mfData.GridData.Elevations.Count; i++)
                {
                    elevation.Add(this._mfData.GridData.Elevations[i]);
                }
                List<GeneralHead> generalHeads = this._mfData.SourceSinks.GeneralHeads.InnerList;

                for (int i = 0; i < generalHeads.Count; i++)
                {
                    if (generalHeads[i].FirstHead < elevation[generalHeads[i].K - 1][generalHeads[i].I - 1, generalHeads[i].J - 1])
                    {
                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Error, PackageType.GENERALHEAD_mf, ErrorType.HeadAndElevation);
                        string str = CheckErrorType.Error.ToString() + "  " + PackageType.GENERALHEAD_mf.ToString() + "   " + ErrorType.HeadAndElevation.ToString() + "   " + generalHeads[i].K.ToString() + "   " + "层"+generalHeads[i].Index + "单元格的网格底部高程值不能大于通用水头的Stage值。";
                        checkResult.SetMessage(str);
                        condu.Add(checkResult);
                    }
                    //E2边界和含水层界面的水力传导系数不能为负值
                    if (generalHeads[i].FirstConductance < 0)
                    {
                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Error, PackageType.GENERALHEAD_mf, ErrorType.LowerThanZero);
                        string str = CheckErrorType.Error.ToString() + "  " + PackageType.GENERALHEAD_mf.ToString() + "   " + ErrorType.LowerThanZero.ToString() + "   " + generalHeads[i].K.ToString() + "   " + "层" + generalHeads[i].Index + "单元格的网格边界含水层界面的水力传导系数不能为负值。";
                        checkResult.SetMessage(str);
                        conduLowerZero.Add(checkResult);
                    }
                }
                if (displaySetup.IsDisplayAllErrors)
                {
                    arryCheck.AddRange(condu);
                    arryCheck.AddRange(conduLowerZero);
                }
                else
                {
                    for (int i = 0; i < condu.Count; i++)
                    {
                        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
                        {
                            arryCheck.Add(condu[i]);
                        }
                    }
                    for (int i = 0; i < conduLowerZero.Count; i++)
                    {
                        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
                        {
                            arryCheck.Add(conduLowerZero[i]);
                        }
                    }
                }
            }

            return arryCheck;
        }
        /// <summary>
        /// Recharge包
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckRechargePackage(ListDisplaySetup displaySetup)
        {
            //W1：补给通量全是0的情况下给出警告信息。
            List<CheckResultMessage> arryCheck = new List<CheckResultMessage>();
          
            if (!this._mfData.SourceSinks.Recharges.Enabled)
            {
                return arryCheck;
            }
            if (displaySetup.IsSuppressWarnings)
            {
                return arryCheck;
            }
            if (this._mfData != null)
            {
                List<double[,]> elevation = this._mfData.GridData.Elevations;
                Recharge recharges = this._mfData.SourceSinks.Recharges.Recharge;

                for (int i = 0; i < recharges.Periods.Count; i++)
                {
                    //猜测Flux字段就是补给通量
                    bool b = IsLayerDataIsAllZero(recharges.Periods[i].Flux);
                    if (b)
                    {
                        CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.RECHARGE_mf, ErrorType.AllZero);
                        string str = CheckErrorType.Warning.ToString() + "  " + PackageType.RECHARGE_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (i + 1).ToString() + "   " + "层网格的补给通量不能全是0";
                        checkResult.SetMessage(str);
                        arryCheck.Add(checkResult);
                    }
                }
                return arryCheck;
            }



            //E1：补给层号数组IRCH应该在层号应该是存在的.....不知道这是什么东西,未写


            return arryCheck;
        }
        /// <summary>
        /// EVT包
        /// </summary>
        /// <param name="displaySetup"></param>
        /// <returns></returns>
        private List<CheckResultMessage> CheckEVTPackage(ListDisplaySetup displaySetup)
        {
            List<CheckResultMessage> arryCheck = new List<CheckResultMessage>();
            if (!this._mfData.SourceSinks.Evts.Enabled)
            {
                return arryCheck;
            }
            List<double[,]> elevation = this._mfData.GridData.Elevations;
            List<CheckResultMessage> arrylisErro = new List<CheckResultMessage>(); //记录多少个错误
            if (this._mfData != null)
            {

                Evapotranspiration evts = this._mfData.SourceSinks.Evts.EVT;
                for (int i = 0; i < evts.Periods.Count; i++)
                {
                    bool b = IsLayerDataIsAllZero(evts.Periods[i].Elevation);
                    if (!displaySetup.IsSuppressWarnings)
                    {
                        //W2：ET 界面的高程surf全是0的情况下给出警告信息

                        //if (this ._mfData.SourceSinks.Evts.EVT.Periods[0].
                        if (b)
                        {
                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.EVT_mf, ErrorType.AllZero);
                            string str = CheckErrorType.Warning.ToString() + "  " + PackageType.EVT_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (i + 1).ToString() + "   " + "层网格的蒸散高程不能全是0";
                            checkResult.SetMessage(str);
                            arryCheck.Add(checkResult);
                        }
                        //W3：ET终止深度EXDP全是0的情况下给出警告信息
                        b = IsLayerDataIsAllZero(evts.Periods[i].ExtinctDepth);
                        if (b)
                        {
                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.EVT_mf, ErrorType.AllZero);
                            string str = CheckErrorType.Warning.ToString() + "  " + PackageType.EVT_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (i + 1).ToString() + "   " + "层网格的蒸散终止深度不能全是0";
                            checkResult.SetMessage(str);
                            arryCheck.Add(checkResult);
                        }
                        // W1：最大蒸散通量EVTR全是0的情况下给出警告信息,不确定是此字段，猜测是
                        b = IsLayerDataIsAllZero(evts.Periods[i].MaxETRate);
                        if (b)
                        {
                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Warning, PackageType.EVT_mf, ErrorType.AllZero);
                            string str = CheckErrorType.Warning.ToString() + "  " + PackageType.EVT_mf.ToString() + "   " + ErrorType.AllZero.ToString() + "   " + (i + 1).ToString() + "   " + "层网格的蒸散最大蒸散通量不能全是0";
                            checkResult.SetMessage(str);
                            arryCheck.Add(checkResult);
                        }
                    }


                    if (elevation.Count > 1)
                    {
                        //E1：ET 界面的高程surf不能低于第一层网格底部海拔
                        b = IsFirstHasDataLowerThanSecondData(evts.Periods[i].Elevation, elevation[1]);
                        if (b)
                        {
                            CheckResultMessage checkResult = new CheckResultMessage(CheckErrorType.Error, PackageType.EVT_mf, ErrorType.BotAndTopElevation);
                            string str = CheckErrorType.Error.ToString() + "  " + PackageType.EVT_mf.ToString() + "   " + ErrorType.BotAndTopElevation.ToString() + "   " + (i + 1).ToString() + "   " + "层网格的ET界面的高程不能小于第一层网格底部海拔。";
                            checkResult.SetMessage(str);
                            arrylisErro.Add(checkResult);
                        }
                    }
                }
                if (displaySetup.IsDisplayAllErrors)
                {
                    for (int i = 0; i < arrylisErro.Count ; i++)
                    {
                        arryCheck.Add(arrylisErro[i]);
                    }
                }
                else
                {
                    List<CheckResultMessage> arryCheckCount = new List<CheckResultMessage>();
                    for (int i = 0; i < arrylisErro.Count ; i++)
                    {
                        if ((i + 1) <= displaySetup.DisplayErrorsMaxNum)
                        {
                            arryCheck.Add(arrylisErro[i]);
                        }
                    }
                    return arryCheck;
                }
                 
               
            }

            return arryCheck;
        }

        #endregion










        #endregion



        #region 内部辅助函数

        /// <summary>
        /// 层数据是否全部为0的判断
        /// true  全部为0；false  不是全部为0
        /// </summary>
        /// <param name="layerInitHead"></param>
        /// <returns></returns>
        private bool IsLayerDataIsAllZero(double[,] layerData)
        {
            if (layerData != null)
            {


                for (int row = 0; row < layerData.GetLength(0); row++)
                {
                    for (int col = 0; col < layerData.GetLength(1); col++)
                    {
                        if (layerData[row, col] != 0)
                        {
                            //isNotZeroNum = isNotZeroNum + 1;
                            return false;
                        }
                    }
                }

                return true;


            }
            else
            {
                return true;

            }


        }

        /// <summary>
        /// 相同的row，col前后两个数据大小比较
        /// true  存在第一个值小于第二个值；false  不存在
        /// </summary>
        /// <param name="firstData"></param>
        /// <param name="secondData"></param>
        /// <returns></returns>
        private bool IsFirstHasDataLowerThanSecondData(double[,] firstData, double[,] secondData)
        {

            if (firstData != null && secondData != null)
            {
                if (firstData.GetLength(0) != secondData.GetLength(0) || firstData.GetLength(1) != secondData.GetLength(1))
                {
                    return true;
                }



                for (int row = 0; row < firstData.GetLength(0); row++)
                {
                    for (int col = 0; col < firstData.GetLength(1); col++)
                    {
                        if (firstData[row, col] < secondData[row, col])
                        {

                            return true;
                        }
                    }
                }

                return false;

            }
            else
            {

                return true;
            }


        }


        /// <summary>
        /// 判断第一个数是否小于第而个数值的一半 
        /// 
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        private bool IsFirstLowerThanSecondHalf(double firstPoint, double secondPoint,double thirdPoint)
        {
            double cellLeftLength = Math.Abs(secondPoint -firstPoint );
            double cellRightLen = Math.Abs(thirdPoint -secondPoint );

            if (cellLeftLength < cellRightLen * 0.5  ||(cellRightLen <cellLeftLength *0.5))
            {
                return true;
            }
            else
            {
                return false;

            }

        }



        #endregion

    }
}
